package com.eaoa.uc.permission.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.base.EABaseAction;
import com.eaoa.query.pub.PubAccountQuery;
import com.eaoa.query.pub.PubRoleQuery;
import com.eaoa.vo.pub.PubAccount;
import com.eaoa.vo.pub.PubRole;
import com.stony.core.util.CoreUtils;

public class RoleEmployeeAction extends EABaseAction {
	protected ActionForward doWork(ActionMapping mapping, ActionForm form,
	HttpServletRequest request, HttpServletResponse response)
	throws Exception {

		Long roleno = CoreUtils.parseLong(request.getParameter("roleno"));

		PubAccountQuery accountQuery = new PubAccountQuery();
		accountQuery.setRoleno(roleno);
		accountQuery.setIslock("N");
		accountQuery.execute();
		List accounts = accountQuery.getResults();
		
		StringBuffer accountnos = new StringBuffer();
		
		for(int i=0 ; i<accounts.size() ; i++){
			PubAccount account = (PubAccount)accounts.get(i);
			accountnos.append(account.getAccountno()).append(",");
		}
		
		PubRole role= PubRoleQuery.loadByRoleno(roleno);

		request.setAttribute("roleno", roleno);
		request.setAttribute("rolename", role.getRolename());
		request.setAttribute("results", accounts);
		request.setAttribute("selected_empno", accountnos.toString());

		return mapping.findForward("success");
	}

}